﻿using CKS.Core.Framework;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ZR.Model.Models.ProductionControl;

namespace CKS.PLC.Action.Subscription.OP50
{
    /// <summary>
    /// 焊片上料
    /// </summary>
    public class DB3021_Work03Action : PLCAction
    {
        public DB3021_Work03Action(DecodeValue _value) : base(_value)
        {
        }
        public override void Execute()
        {
            var replyPos = Value.GetPosition(3020, 20);
            var result = Value.Value.ToInt();
            if (result == 1)
            {
                //查询子篮
                string bluecode = Value.GetLinkData(1).ToString();
                int stock = Value.GetLinkData(2).ToInt();
                UpdateBasketStock(bluecode, stock);
                AckWriteInt16(replyPos, 1);
                EventBus.AddLog($"OP50-焊片上料-子篮{bluecode}剩余数量{stock}");
            }
            else
            {
                AckWriteInt16(replyPos, 0);
                EventBus.AddLog("OP50-焊片上料-状态重置");

            }
        }
    }
}
